<?php

namespace app\common\model\stall;

use app\common\model\BaseModel;

class Product extends BaseModel
{
    protected $name = 'stall_product';
    protected $pk = 'id';

    public static function checkDB($stallid, $productid, $checktype = false)
    {
        $where = [];
        if (!$checktype) {
            $where = ['is_delete' => 0];
        }
        return self::where(['stall_id' => $stallid, 'product_id ' => $productid])->where($where)->find();
    }

    public static function updateShowStatus($id, $savedata)
    {
        $model = self::detail($id);
        if ($model) {
            return $model->save(['is_show' => $savedata['is_show'],'product_price' => $savedata['product_price']]);
        } else {
            return (new self)->save($savedata);
        }
    }

    public static function detail($id)
    {
        return (new static())->where('id', '=', $id)->find();
    }
}